/*
 * @Author: 阿芙
 * @Date: 2021-06-07 16:16:55
 * @LastEditTime: 2021-06-07 21:53:32
 * @LastEditors: Please set LastEditors
 * @Description: 
 * @FilePath: /Blog_Web/src/com/HY/Xiao-Jun-Jun/Model/SystemModel/pager.js
 */

/**
 * @description: 处理分页
 * @param {*}
 * @return {*}
 */
class Pager{
    //每页显示多少条记录
    pageSize = null;

    //当前第几页数据
    currrentPage = null;

    //一共有多少条记录
    totalRecord = null;

    /**
     * @description: 一共多少页记录
     * @param {*}
     * @return {*}
     */    
    totalPage = null;

    //显示的数据
    dataList = null;

    /**
     * @description:起始索引 
     * @param {*}
     * @return {*}
     */    
    fromIndex = null;

    /**
     * @description: 
     * @param {*} pageSize 必填，默认值=6，每页显示记录条数
     * @param {*} currrentPage 必填 当前第几页
     * @param {*} totalRecord   一共多少条
     * @param {*} totalPage     一共多少页
     * @param {*} dataList 必填     数据集合
     * @return {*}
     */    
    constructor(pageSize=6,currrentPage,totalRecord,totalPage,dataList){
        this.pageSize = pageSize || 6;
        this.currrentPage = currrentPage || null;
        this.totalRecord = totalRecord || null;
        this.totalPage = totalPage || null;
        this.dataList = dataList || null; 
        this.Pagerhandle();
    };
    /**
     * @description: 计算分页
     * @param {*}
     * @return {*}
     */    
    Pagerhandle(){
        "use static";
            if(this.pageSize != null && this.currrentPage != null){
                this.fromIndex = this.pageSize * (this.currrentPage-1);
            }
    };
    
    SetDataList(data){
        "use static";
        this.dataList = data;
    };

    /**
     * @description: 获取起始索引
     * @param {*}
     * @return {*}
     */    
    GetFromIndex(){
        return this.fromIndex;
    };

    /**
     * @description:查询一共多少条记录 
     * @param {*} value 记录数
     * @return {*}
     */    
    SetTotalRecord(value){
        "use static";
        this.totalRecord = value;
    };

    /**
     * @description:获取 每页显示多少条记录
     * @param {*}
     * @return {*}
     */    
    GetPageSize(){
        "use static";
        return this.pageSize;
    };

    /**
     * @description: 一共多少页
     * @param {*} value 共记录数
     * @return {*}
     */  
    SetTotalPage(value){
        "use static";
        let key = value / this.pageSize
        
        if(key% this.pageSize != 0){
            key += 1;
        }
        this.totalPage = parseInt(key);
    };
};

module.exports = Pager;


/**
 * 
 *  
    let pager = new Pager(6,3);
    pager.SetTotalRecord(100);
    pager.SetTotalPage(100);
    console.log(pager.GetFromIndex())
    console.log(pager)
 */